/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.checkinfos.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.modules.checkinfos.entity.Checkinfos;
import com.fosung.frame.modules.checkinfos.service.CheckinfosService;

/**
 * 审核记录Controller
 * @author zhangfn
 * @version 2017-08-30
 */
@Controller
@RequestMapping(value = "${adminPath}/checkinfos/checkinfos")
public class CheckinfosController extends BaseController {

	@Autowired
	private CheckinfosService checkinfosService;
	
	@ModelAttribute
	public Checkinfos get(@RequestParam(required=false) String id) {
		Checkinfos entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = checkinfosService.get(id);
		}
		if (entity == null){
			entity = new Checkinfos();
		}
		return entity;
	}
	
	@RequiresPermissions("checkinfos:checkinfos:view")
	@RequestMapping(value = {"list", ""})
	public String list(Checkinfos checkinfos, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Checkinfos> page = checkinfosService.findPage(new Page<Checkinfos>(request, response), checkinfos); 
		model.addAttribute("page", page);
		return "modules/checkinfos/checkinfosList";
	}

	@RequiresPermissions("checkinfos:checkinfos:view")
	@RequestMapping(value = "form")
	public String form(Checkinfos checkinfos, Model model) {
		model.addAttribute("checkinfos", checkinfos);
		return "modules/checkinfos/checkinfosForm";
	}

	@RequiresPermissions("checkinfos:checkinfos:edit")
	@RequestMapping(value = "save")
	public String save(Checkinfos checkinfos, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, checkinfos)){
			return form(checkinfos, model);
		}
		checkinfosService.save(checkinfos);
		addMessage(redirectAttributes, "保存审核记录成功");
		return "redirect:"+Global.getAdminPath()+"/checkinfos/checkinfos/?repage";
	}
	
	@RequiresPermissions("checkinfos:checkinfos:edit")
	@RequestMapping(value = "delete")
	public String delete(Checkinfos checkinfos, RedirectAttributes redirectAttributes) {
		checkinfosService.delete(checkinfos);
		addMessage(redirectAttributes, "删除审核记录成功");
		return "redirect:"+Global.getAdminPath()+"/checkinfos/checkinfos/?repage";
	}

}